//
//  SportTopView.m
//  Lightthings
//
//  Created by Hero on 2024/11/16.
//

#import "SportTopView.h"
#import "ZZCircleProgress.h"

@interface SportTopView ()
@property (strong, nonatomic) UILabel *stepValueLab, * stepUnit, *stepLab, * hotValueLab, *hotUnitLab, *hotLab;
@property (nonatomic, strong) ZZCircleProgress * circleProgressView;

@end

@implementation SportTopView

- (void)updateCurrentStep:(long )step CurrentHot:(int)hot Target:(long long)target {
    self.stepValueLab.text = [NSString stringWithFormat:@"%ld",step];
    self.hotValueLab.text = [NSString stringWithFormat:@"%d",hot];
    NSString * num = [NSString stringWithFormat:@"%@\n",SWString(@"Goal")];
    _circleProgressView.progressLabel.attributedText = [SWTool attS1:num s2:[NSString stringWithFormat:@"%lld",target] f1:U_font(14) c1:[ThemeManager sharedInstance].textColor f2:U_bfont(16) c2:[ThemeManager sharedInstance].textColor];
    self.circleProgressView.progress = (float)step / (float)target;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = KLColor(@"FFFFFF");
        self.layer.cornerRadius = 10;
        self.layer.shadowOpacity = 0.1;
        self.layer.shadowOffset = CGSizeZero;
        self.layer.shadowRadius = 10;
        
        [self stepValueLab];
        [self hotValueLab];
        
        [self addSubview:self.circleProgressView];
        [_circleProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeLV(self.width/ 2);
            kMakeCenterYV(0);
            kMakeWHV(100, 100);
        }];
        
    }
    return self;
}

- (ZZCircleProgress *)circleProgressView {
    if (!_circleProgressView) {
        _circleProgressView = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(0, 0, 110, 110) pathBackColor:[ThemeManager sharedInstance].circleBackColor pathFillColor:[ThemeManager sharedInstance].circleFillColor startAngle:-90 strokeWidth:7];
        _circleProgressView.reduceAngle = 0;//整合进度条缺少30度
    //    self.circleProgressView.pointImage.image = [UIImage imageNamed:@"test"];//设置小圆点图片
        _circleProgressView.duration = 0.2;//动画时长。默认为1.5
        _circleProgressView.showProgressText = YES;//是否显示默认进度文本。默认为YES
        _circleProgressView.increaseFromLast = NO;//进度条动画是否从上次进度开始动画。默认为NO
        _circleProgressView.startAngle = 90;
    
        _circleProgressView.showPoint = YES;//是否显示默认小圆点。默认为YES·
        _circleProgressView.progressLabel.numberOfLines = 2;
        
        NSString * num = [NSString stringWithFormat:@"%@\n",SWString(@"Goal")];
        _circleProgressView.progressLabel.attributedText = [SWTool attS1:num s2:@"0" f1:U_font(14) c1:[ThemeManager sharedInstance].textColor f2:U_bfont(16) c2:[ThemeManager sharedInstance].textColor];
        
        _circleProgressView.progress = 0.0;
    }
    return _circleProgressView;
}


- (UILabel *)stepValueLab {
    if (!_stepValueLab) {
        UILabel * obj = [[UILabel alloc] init];
        obj.font = U_sfont(17);
        obj.text = @"0";
        [self addSubview:_stepValueLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeLV(15); kMakeTV(15);
            kMakeHV(20);
        }];
        
        _stepUnit = [[UILabel alloc] init];
        _stepUnit.font = U_font(11);
        _stepUnit.text = SWString(@"步");
        [self addSubview:_stepUnit];
        [_stepUnit mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeL(obj.mas_right).offset(2);
            kMakeB(obj.mas_bottom);
        }];
        
        UIImageView * icon =  [JYInitializer jy_initImageViewWithImage:U_imageNamed(@"icon_sport_step") on:self layout:^(MASConstraintMaker * _Nonnull make) {
            kMakeL(obj.mas_left);
            kMakeWHV(15, 15);
            kMakeT(obj.mas_bottom).offset(0);
        }];
        
        _stepLab = [[UILabel alloc] init];
        _stepLab.text = SWString(@"当前步数");
        _stepLab.textColor = KLColor(@"#999999");
        _stepLab.font = U_font(11);
        [self addSubview:_stepLab];
        [_stepLab mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeL(obj.mas_left).offset(17);
            kMakeB(icon.mas_bottom);
        }];
        
    }
    return _stepValueLab;
}


- (UILabel *)hotValueLab {
    if (!_hotValueLab) {
        UILabel * obj = [[UILabel alloc] init];
        obj.font = U_sfont(17);
        obj.text = @"0";
        [self addSubview:_hotValueLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeLV(15); kMakeTV(self.height / 2);
            kMakeHV(20);
        }];
        
        _hotUnitLab = [[UILabel alloc] init];
        _hotUnitLab.font = U_font(11);
        _hotUnitLab.text = SWString(@"Kcal");
        [self addSubview:_hotUnitLab];
        [_hotUnitLab mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeL(obj.mas_right).offset(2);
            kMakeB(obj.mas_bottom);
        }];
        
        UIImageView * icon =  [JYInitializer jy_initImageViewWithImage:U_imageNamed(@"icon_sport_cal") on:self layout:^(MASConstraintMaker * _Nonnull make) {
            kMakeL(obj.mas_left);
            kMakeWHV(15, 15);
            kMakeT(obj.mas_bottom).offset(0);
        }];
        
        _hotLab = [[UILabel alloc] init];
        _hotLab.text = SWString(@"当前热量");
        _hotLab.textColor = KLColor(@"#999999");
        _hotLab.font = U_font(11);
        [self addSubview:_hotLab];
        [_hotLab mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeL(obj.mas_left).offset(17);
            kMakeB(icon.mas_bottom);
        }];
    }
    return _hotValueLab;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
